from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-18 14:12:18.473657
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 18, Sep, 2021
Time: 14:12:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.2278
Nobs: 418.000 HQIC: -46.7532
Log likelihood: 4595.16 FPE: 3.51735e-21
AIC: -47.0967 Det(Omega_mle): 2.84321e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.438970 0.092750 4.733 0.000
L1.Burgenland 0.103493 0.047888 2.161 0.031
L1.Kärnten -0.114617 0.023905 -4.795 0.000
L1.Niederösterreich 0.160887 0.102573 1.569 0.117
L1.Oberösterreich 0.119225 0.100755 1.183 0.237
L1.Salzburg 0.284178 0.050305 5.649 0.000
L1.Steiermark 0.026618 0.066721 0.399 0.690
L1.Tirol 0.108457 0.052682 2.059 0.040
L1.Vorarlberg -0.107684 0.047357 -2.274 0.023
L1.Wien -0.012346 0.091729 -0.135 0.893
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013878 0.213814 0.065 0.948
L1.Burgenland -0.048675 0.110394 -0.441 0.659
L1.Kärnten 0.036880 0.055107 0.669 0.503
L1.Niederösterreich -0.216718 0.236459 -0.917 0.359
L1.Oberösterreich 0.482276 0.232267 2.076 0.038
L1.Salzburg 0.306646 0.115966 2.644 0.008
L1.Steiermark 0.118710 0.153809 0.772 0.440
L1.Tirol 0.313933 0.121446 2.585 0.010
L1.Vorarlberg 0.002114 0.109170 0.019 0.985
L1.Wien 0.002755 0.211459 0.013 0.990
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.246206 0.047185 5.218 0.000
L1.Burgenland 0.090823 0.024362 3.728 0.000
L1.Kärnten -0.001928 0.012161 -0.159 0.874
L1.Niederösterreich 0.210721 0.052182 4.038 0.000
L1.Oberösterreich 0.168475 0.051257 3.287 0.001
L1.Salzburg 0.034146 0.025592 1.334 0.182
L1.Steiermark 0.018134 0.033943 0.534 0.593
L1.Tirol 0.068546 0.026801 2.558 0.011
L1.Vorarlberg 0.056944 0.024092 2.364 0.018
L1.Wien 0.109585 0.046665 2.348 0.019
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182570 0.046120 3.959 0.000
L1.Burgenland 0.049025 0.023812 2.059 0.040
L1.Kärnten -0.006597 0.011886 -0.555 0.579
L1.Niederösterreich 0.137932 0.051004 2.704 0.007
L1.Oberösterreich 0.318084 0.050100 6.349 0.000
L1.Salzburg 0.100657 0.025014 4.024 0.000
L1.Steiermark 0.131611 0.033177 3.967 0.000
L1.Tirol 0.076203 0.026196 2.909 0.004
L1.Vorarlberg 0.056370 0.023548 2.394 0.017
L1.Wien -0.046066 0.045612 -1.010 0.313
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205978 0.091682 2.247 0.025
L1.Burgenland -0.048880 0.047336 -1.033 0.302
L1.Kärnten -0.034763 0.023629 -1.471 0.141
L1.Niederösterreich 0.107452 0.101392 1.060 0.289
L1.Oberösterreich 0.164986 0.099594 1.657 0.098
L1.Salzburg 0.254111 0.049725 5.110 0.000
L1.Steiermark 0.080662 0.065952 1.223 0.221
L1.Tirol 0.126134 0.052075 2.422 0.015
L1.Vorarlberg 0.115695 0.046811 2.472 0.013
L1.Wien 0.032555 0.090672 0.359 0.720
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.029754 0.070853 0.420 0.675
L1.Burgenland 0.023865 0.036582 0.652 0.514
L1.Kärnten 0.052358 0.018261 2.867 0.004
L1.Niederösterreich 0.213265 0.078358 2.722 0.006
L1.Oberösterreich 0.332904 0.076969 4.325 0.000
L1.Salzburg 0.045484 0.038429 1.184 0.237
L1.Steiermark -0.005461 0.050969 -0.107 0.915
L1.Tirol 0.113632 0.040245 2.824 0.005
L1.Vorarlberg 0.066323 0.036177 1.833 0.067
L1.Wien 0.128771 0.070073 1.838 0.066
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186008 0.086813 2.143 0.032
L1.Burgenland 0.018740 0.044823 0.418 0.676
L1.Kärnten -0.057510 0.022375 -2.570 0.010
L1.Niederösterreich -0.117753 0.096008 -1.226 0.220
L1.Oberösterreich 0.184347 0.094306 1.955 0.051
L1.Salzburg 0.030475 0.047085 0.647 0.517
L1.Steiermark 0.300439 0.062450 4.811 0.000
L1.Tirol 0.487117 0.049310 9.879 0.000
L1.Vorarlberg 0.075972 0.044326 1.714 0.087
L1.Wien -0.105272 0.085857 -1.226 0.220
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162255 0.094521 1.717 0.086
L1.Burgenland -0.010145 0.048802 -0.208 0.835
L1.Kärnten 0.063402 0.024361 2.603 0.009
L1.Niederösterreich 0.192597 0.104532 1.842 0.065
L1.Oberösterreich -0.129505 0.102678 -1.261 0.207
L1.Salzburg 0.236177 0.051265 4.607 0.000
L1.Steiermark 0.155294 0.067994 2.284 0.022
L1.Tirol 0.046837 0.053688 0.872 0.383
L1.Vorarlberg 0.130636 0.048261 2.707 0.007
L1.Wien 0.155186 0.093480 1.660 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486840 0.051265 9.497 0.000
L1.Burgenland -0.007734 0.026469 -0.292 0.770
L1.Kärnten -0.010128 0.013213 -0.767 0.443
L1.Niederösterreich 0.203293 0.056695 3.586 0.000
L1.Oberösterreich 0.259709 0.055689 4.664 0.000
L1.Salzburg 0.021260 0.027805 0.765 0.444
L1.Steiermark -0.024595 0.036878 -0.667 0.505
L1.Tirol 0.068306 0.029119 2.346 0.019
L1.Vorarlberg 0.059149 0.026175 2.260 0.024
L1.Wien -0.053087 0.050700 -1.047 0.295
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021795 0.074706 0.140699 0.130973 0.041264 0.075008 -0.004506 0.176376
Kärnten 0.021795 1.000000 -0.044643 0.127290 0.046871 0.069373 0.454300 -0.093659 0.091866
Niederösterreich 0.074706 -0.044643 1.000000 0.282080 0.082721 0.265371 0.020430 0.137732 0.258924
Oberösterreich 0.140699 0.127290 0.282080 1.000000 0.180083 0.285028 0.155084 0.100147 0.138231
Salzburg 0.130973 0.046871 0.082721 0.180083 1.000000 0.125972 0.055711 0.104934 0.052921
Steiermark 0.041264 0.069373 0.265371 0.285028 0.125972 1.000000 0.130508 0.090242 -0.023388
Tirol 0.075008 0.454300 0.020430 0.155084 0.055711 0.130508 1.000000 0.045118 0.116560
Vorarlberg -0.004506 -0.093659 0.137732 0.100147 0.104934 0.090242 0.045118 1.000000 -0.048012
Wien 0.176376 0.091866 0.258924 0.138231 0.052921 -0.023388 0.116560 -0.048012 1.000000